<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <%@include file="/WEB-INF/common/hplus-css.jsp"%>
    <%@ include file="/WEB-INF/common/kindetor.jsp"%>
</head>
<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox">
                    <div class="ibox-content">
                        <form action="${path}/article/edit" class="form-horizontal m-t" id="userForm" method="post">    
                        	<input type="hidden" name="id" value="${article.id }"/>                   	
                            <div class="form-group">
                                <label class="col-sm-3 control-label">公告标题：</label>
                                <div class="col-sm-8">
                              
                                     <input type="text" id="title" name="title"  class="form-control" required="" value="${article.title }" >
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">公告所属类别：</label>
                                <div class="col-sm-8">
                                    <select class="form-control m-b" name="genreCode">
                                     <option value="0" <c:if test="${article.genreCode=='0'}">selected</c:if>>登录首页幻灯片</option>
                                        <option value="1" <c:if test="${article.genreCode=='1'}">selected</c:if>>政策信息</option>
                                        <option value="2" <c:if test="${article.genreCode=='2'}">selected</c:if>>排爆状态</option>
                                         <option value="3" <c:if test="${article.genreCode=='3'}">selected</c:if>>页轮播幻灯片</option>
                                          <option value="4" <c:if test="${article.genreCode=='4'}">selected</c:if>>封面大图</option>
                                            <option value="5" <c:if test="${article.genreCode=='5'}">selected</c:if>>用户指南</option>
                                    </select>
                                    <!-- <input type="hidden" class="form-control" name="genreName" id="genreName"> -->
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">公告摘要：</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control" name="summary"   value="${article.summary }">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">外部链接：</label>
                                <div class="col-sm-8">
                                  <input type="text" name="url" value="${article.url }"/>
								</div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">封面图片：</label>
                              <!--   <div class="col-sm-8"> -->
                                	<!-- <img alt="封面图片" src="">
                                    <input type="file" class="form-control" name="coverImageUrl"> -->
                               		<div class="col-sm-6">
										<div class="input-group">
											<input id="filename" class="form-control" name="coverImageUrl">
											<input type="hidden" id="attachId"
												placeholder="文件上传" name="attachId" minlength="2"
												class="form-control" required="" aria-required="true"
												value="${article.coverImageUrl}"><span class="input-group-btn"> <a
												id="selectfile" onClick="upload('attachId')"
												href="javascript:" class="btn btn-primary">选择文件</a></span>
										</div>
									<!-- </div> -->
                                </div>
                                
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label" >状态：</label>
                                <div class="col-sm-8">
                                    <select class="form-control m-b" name="status">
                                        <option value="1" <c:if test="${article.status=='1' }">selected</c:if>>发布</option>
                                        <option value="2" <c:if test="${article.status=='2' }">selected</c:if>>草稿</option>
                                    </select>
                                </div>
                            </div>
                             <div class="form-group">
                                <label class="col-sm-3 control-label">内容：</label>
                                 <div class="col-sm-6">
									<textarea placeholder="公告信息内容" name="content" class="form-control" required="" style="height:350px;">${article.content}</textarea>
                                  </div>
                            </div>
                            <div class="form-group">
                                <div class="col-sm-4 col-sm-offset-3">
                                    <button class="btn btn-primary" id="edit-btn" type="button">发布</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <%@include file="/WEB-INF/common/hplus-js.jsp"%>
    <script src="${path}/assets/hplus/js/demo/form-validate-demo.js"></script>
    <script>
    var clz = null;//name属性的值
    function upload(data) {
        //iframe窗 workRange
        clz = data;
        var proAreaCode = $(".workRange").find("option:selected").text();
        index = layer.open({
            type: 2,
            content: '${path}/common/selectfile', //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
            area: ['800px', '500px'],
            title: ['文件上传页面', 'font-size:18px;']
        });
    }
    function testA(path, name) {
        layer.close(index);
        console.log(path)
        $("input[id='filename']").val(name);//jquery通过name属性获取html对象并赋值
        $("input[name='" + clz + "']").val(path);//jquery通过name属性获取html对象并赋值
        $('#persionImg').hide();
    }
    
        $(document).ready(function () {
        	
        	$("#userForm").validate();
            $('.i-checks').iCheck({
                checkboxClass: 'icheckbox_square-green',
                radioClass: 'iradio_square-green',
            });
            
            $("#edit-btn").click(function() {
				
            	var valid = $("#userForm").valid();
            	if(valid) {
            		/* var genreCode=$("input[name='genreCode']").text();
            		if (genreCode=='1') {
            			$("#genreName").val("政策信息");
					}else{
						$("#genreName").val("排爆动态");
					} */
            		$("#userForm").ajaxSubmit({
                        dataType: "json",
                        success: function (json) {
                            var code = json.code;
                            if(code == 0){
                            	layer.msg('更新成功', {icon: 1});
                                setTimeout(function(){
                                	window.parent.location.reload();
                                	parent.parent.layer.closeAll();
                                }, 1000);
                            }else{
                            	layer.msg(json.msg, {icon: 5,time:2000});
                            }
                        },
                        error:function(){
                        	layer.msg('修改发生错误', {icon: 5});
                        }
                    });
            	}
            });
        });
        //------------------富文本输入框初始化开始-------------------------------
    	var editor1;
    	var genreOldVal = "";
    	
    	KindEditor.ready(function(K) {
    			editor1 = K.create('textarea[name="content"]', {
    			uploadJson : '${path }/servlet/uploadKindeditorServlet.html',
    			fileManagerJson : '${path }/servlet/fileManageKindeditorServlet.html',
    			allowFileManager : true,
    			afterCreate : function() { 
    				this.sync(); 
    			},afterBlur : function() {
    				this.sync();
    				K.ctrl(document, 13, function() {
    					K('form[name=dataForm]')[0].submit();
    				});
    				K.ctrl(this.edit.doc, 13, function() {
    					K('form[name=dataForm]')[0].submit();
    				});
    			}
    		});
    		prettyPrint();
    	});
    	
    </script>
</body>
</html>
